package com.example.xiaodu.yuejian12.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xiaodu.yuejian12.Bean.MasterBean;
import com.example.xiaodu.yuejian12.Bean.TrainBean;
import com.example.xiaodu.yuejian12.Listener.RetrofitListener;
import com.example.xiaodu.yuejian12.Model.UserModel;
import com.example.xiaodu.yuejian12.R;
import com.squareup.picasso.Picasso;

import static com.example.xiaodu.yuejian12.R.id.signUp;

public class TrainDetailActivity extends AppCompatActivity {

    private TextView trainName,trainIntro,trainTime,trainPrice,trainPlace;
    private ImageView imageView;
    private UserModel userModel;
    private Button signUP;
    private int trainID;
    private RetrofitListener<TrainBean> listener;

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_train_detail);

        initView();
        initListener();
        getData();
        initClick();
    }

    public void initView(){
        imageView=(ImageView)findViewById(R.id.train_picture);
        trainName=(TextView)findViewById(R.id.name);
        trainIntro=(TextView)findViewById(R.id.intro);
        trainTime=(TextView)findViewById(R.id.time);
        trainPrice=(TextView)findViewById(R.id.price);
        trainPlace=(TextView)findViewById(R.id.place);
        signUP=(Button)findViewById(signUp);

    }

    public void initListener(){
        listener=new RetrofitListener<TrainBean>() {
            @Override
            public void onSuccess(TrainBean trainBean) {
                trainName.setText(trainBean.getTname());
                trainTime.setText(trainBean.getTtime());
                trainIntro.setText(trainBean.getTintro());
                trainPrice.setText(trainBean.getTprice());
                trainPlace.setText(trainBean.getTplace());

                Picasso.with(imageView.getContext()).load("http://10.0.2.2/yuejian/public/static/train/"+trainBean.getTpic()).into(imageView);

            }

            @Override
            public void onFail(String msg) {

            }
        };
    }

    public void getData(){
        userModel=new UserModel();
        userModel.getTrainDetail(getIntent().getIntExtra("trainID",1),listener);
    }


    public void initClick(){
        signUP.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Intent intent=new Intent(TrainDetailActivity.this,Signup3Activity.class);
                intent.putExtra("trainID",trainID);
                startActivity(intent);
            }
        });
    }
}
